package cn.dglydrpy.study.common.mybatisPlus.abstractMethod;/*
 * @author LY_飘涯
 * @date 2021/6/29 21:10
 * @description
 */

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;
import org.apache.ibatis.scripting.defaults.RawSqlSource;

public class FindBaseEntityById extends AbstractMethod {
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        // SELECT %s FROM %s WHERE %s=#{%s} %s
        String sql = "select created_user,created_time,last_modified_user,last_modified_time,version,deleted from " + tableInfo.getTableName()
                + " where %s=#{%s} %s";

        SqlSource sqlSource = new RawSqlSource(configuration, String.format(sql,
                tableInfo.getKeyColumn(), tableInfo.getKeyProperty(),
                tableInfo.getLogicDeleteSql(true, false)), Object.class);

        return this.addSelectMappedStatement(mapperClass, "findBaseEntityById", sqlSource, modelClass, tableInfo);
    }
}
